package com.fenghongzhang.day012;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


/**
 * A simple {@link Fragment} subclass.
 */
public class LoginFragment extends Fragment {
    private EditText logigName;
    private EditText logigPwd;
    private Button login;
    public LoginFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View inflate = inflater.inflate(R.layout.fragment_login, container, false);
        logigName = (EditText) inflate.findViewById(R.id.logig_name);
        logigPwd = (EditText) inflate.findViewById(R.id.logig_pwd);
        login = (Button) inflate.findViewById(R.id.login);

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = logigName.getText().toString();
                String pwd = logigPwd.getText().toString();


                //登录的时候的时间存,一下. 当app打开的时候,取时间来判断够不够5分钟
                SharedPreferences user = getActivity().getSharedPreferences("user", Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = user.edit();
                edit.putLong("lastTime", System.currentTimeMillis());

                edit.putBoolean("isLogin",true);
                edit.commit();

                //跳转
                Intent intent = new Intent(getActivity(), Main2Activity.class);
                startActivity(intent);

            }

        });

        return inflate;
    }
}
